/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.utils
{
	/**
	 * 字符串工具类
	 * @version v1.0
	 * 
	 */	
	public class BOPStringUtils
	{
		/**
		 * 空字符('') 
		 */		
		private static const EMPTY:String = '';

		/**
		 * 整型-1 
		 */		
		private static const INDEX_NOT_FOUND:int = -1;

		/**
		 * 空白字符串的ascii值
		 */
		private static const WHITE:uint = 32;

		/**
		 * <p>最大的连接字符长度.</p>
		 */
		private static const PAD_LIMIT:uint = 8192;

		/**
		 * <p>返回参数字符串的初始化字符.</p>
		 *
		 * StringUtils.toInitials("stringutils") 		= s
		 * StringUtils.toInitials("stringUtils") 		= su
		 * StringUtils.toInitials("stringUtilsTest") 	= sut
		 */
		public static function toInitials(str:String):String {
			if (isEmpty(str)) {
				return str;
			}
			return str.match(/[A-Z]/g).join('').toLowerCase();
		}

		/**
		 * <p>如果参数字符串中间存在换行,则去除.并返回去除后的字符串.</p>
		 *
		 * <pre>
		 * StringUtils.chomp(null)          = null
		 * StringUtils.chomp("")            = ""
		 * StringUtils.chomp("abc \r")      = "abc "
		 * StringUtils.chomp("abc\n")       = "abc"
		 * StringUtils.chomp("abc\r\n")     = "abc"
		 * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n"
		 * StringUtils.chomp("abc\n\r")     = "abc\n"
		 * StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc"
		 * StringUtils.chomp("\r")          = ""
		 * StringUtils.chomp("\n")          = ""
		 * StringUtils.chomp("\r\n")        = ""
		 * </pre>
		 *
		 */
		public static function chomp(str:String):String {
			return chompString(str, '(\r\n|\r|\n)');
		}

		/**
		 * <p>去掉字符串中固定的字符后的字符(含固定字符串).
		 * </p>
		 *
		 * <pre>
		 * StringUtils.chompString(null, *)         = null
		 * StringUtils.chompString("", *)           = ""
		 * StringUtils.chompString("foobar", "bar") = "foo"
		 * StringUtils.chompString("foobar", "baz") = "foobar"
		 * StringUtils.chompString("foo", "foo")    = ""
		 * StringUtils.chompString("foo ", "foo")   = "foo "
		 * StringUtils.chompString(" foo", "foo")   = " "
		 * StringUtils.chompString("foo", "foooo")  = "foo"
		 * StringUtils.chompString("foo", "")       = "foo"
		 * StringUtils.chompString("foo", null)     = "foo"
		 * </pre>
		 *
		 */
		public static function chompString(str:String, separator:String):String {
			if (isEmpty(str) || separator == null) {
				return str;
			}
			return str.replace(new RegExp(separator + '$', ''), '')
		}

		/**
		 * 替换字串中的所有的空格字符.
		 * 
		 * <pre>
		 * StringUtils.trim(null)          = null
		 * StringUtils.trim("")            = ""
		 * StringUtils.trim("     ")       = ""
		 * StringUtils.trim("abc")         = "abc"
		 * StringUtils.trim("    abc    ") = "abc"
		 * </pre>
		 *
		 */
		public static function trim(str:String):String {
			if (str == null) {
				return null;
			}
			return str.replace(/^\s*/, '').replace(/\s*$/, '');
		}

		/**
		 * <p>去除字符串中所有特定的字符.
		 *
		 * <pre>
		 * StringUtils.deleteSpaces(null)           = null
		 * StringUtils.deleteSpaces("")             = ""
		 * StringUtils.deleteSpaces("abc")          = "abc"
		 * StringUtils.deleteSpaces(" \tabc \n ") = " abc  "
		 * StringUtils.deleteSpaces("a\nb\tc     ") = "abc     "
		 * </pre>
		 *
		 * <p>特定的字符包含: <code>{'\t', '\r', '\n', '\b'}</code>
		 * </p>
		 *
		 */
		public static function deleteSpaces(str:String):String {
			return deleteFromString(str, /\t|\r|\n|\b/g);
		}

		/**
		 * <p>去除字符串中间所有的空格.</p>
		 *
		 * <pre>
		 * StringUtils.deleteWhitespace(null)         = null
		 * StringUtils.deleteWhitespace("")           = ""
		 * StringUtils.deleteWhitespace("abc")        = "abc"
		 * StringUtils.deleteWhitespace("   ab  c  ") = "abc"
		 * </pre>
		 *
		 */
		public static function deleteWhitespace(str:String):String {
			return deleteFromString(str, /\s/g);
		}

		private static function deleteFromString(str:String, pattern:RegExp):String {
			if (isEmpty(str)) {
				return str;
			}
			return str.replace(pattern, '');
		}

		/**
		 * <p>获得固定位置左侧的所有字符.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.left(null, *)    = null
		 * StringUtils.left(*, -ve)     = ""
		 * StringUtils.left("", *)      = ""
		 * StringUtils.left("abc", 0)   = ""
		 * StringUtils.left("abc", 2)   = "ab"
		 * StringUtils.left("abc", 4)   = "abc"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param len  截取的固定位置
		 * @return String
		 */
		public static function left(str:String, len:int):String {
			if (str == null) {
				return null;
			}

			if (len < 0) {
				return EMPTY;
			}

			if (str.length <= len) {
				return str;
			}
			return str.substring(0, len);
		}

		/**
		 * <p>将给定的字符串置中,并满足长度为给定长度,左侧和右侧以给定的字符串填充.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.center(null, *, *)     = null
		 * StringUtils.center("", 4, " ")     = "    "
		 * StringUtils.center("ab", -1, " ")  = "ab"
		 * StringUtils.center("ab", 4, " ")   = " ab "
		 * StringUtils.center("abcd", 2, " ") = "abcd"
		 * StringUtils.center("a", 4, " ")    = " a  "
		 * StringUtils.center("a", 4, "yz")   = "yayz"
		 * StringUtils.center("abc", 7, null) = "  abc  "
		 * StringUtils.center("abc", 7, "")   = "  abc  "
		 * </pre>
		 *
		 */
		public static function center(str:String, size:int, padStr:String):String {
			if (str == null || size <= 0) {
				return str;
			}

			if (isEmpty(padStr)) {
				padStr = " ";
			}
			var strLen:int = str.length;
			var pads:int = size - strLen;

			if (pads <= 0) {
				return str;
			}
			str = leftPad(str, strLen + pads / 2, padStr);
			str = rightPad(str, size, padStr);

			return str;
		}

		/**
		 * 在源字符串左侧补充字符串,并满足长度为size.如长度小于源代码长度,则直接返回源字符串.
		 *
		 * <pre>
		 * StringUtils.leftPad(null, *, *)      = null
		 * StringUtils.leftPad("", 3, "z")      = "zzz"
		 * StringUtils.leftPad("bat", 3, "yz")  = "bat"
		 * StringUtils.leftPad("bat", 5, "yz")  = "yzbat"
		 * StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat"
		 * StringUtils.leftPad("bat", 1, "yz")  = "bat"
		 * StringUtils.leftPad("bat", -1, "yz") = "bat"
		 * StringUtils.leftPad("bat", 5, null)  = "  bat"
		 * StringUtils.leftPad("bat", 5, "")    = "  bat"
		 * </pre>
		 *
		 * @param str 源字符串
		 * @param size 补位后的字符串长度
		 * @param padStr  补位的字符串
		 */
		public static function leftPad(str:String, size:int, padStr:String):String {
			if (str == null) {
				return null;
			}

			if (isEmpty(padStr)) {
				padStr = " ";
			}
			var padLen:int = padStr.length;
			var strLen:int = str.length;
			var pads:int = size - strLen;

			if (pads <= 0) {
				return str; // returns original String when possible
			}

			if (padLen == 1 && pads <= PAD_LIMIT) {
				return leftPadChar(str, size, padStr.charAt(0));
			}

			if (pads == padLen) {
				return padStr.concat(str);
			} else if (pads < padLen) {
				return padStr.substring(0, pads).concat(str);
			} else {
				var padding:Array = [];
				var padChars:Array = padStr.split("");

				for (var i:int = 0; i < pads; i++) {
					padding[i] = padChars[i % padLen];
				}
				return padding.join("").concat(str);
			}
		}

		/**
		 * 在源字符串左侧补充字符,并满足长度为size.如长度小于源代码长度,则直接返回源字符串.
		 * 
		 * <pre>
		 * StringUtils.leftPadChar(null, *, *)     = null
		 * StringUtils.leftPadChar("", 3, 'z')     = "zzz"
		 * StringUtils.leftPadChar("bat", 3, 'z')  = "bat"
		 * StringUtils.leftPadChar("bat", 5, 'z')  = "zzbat"
		 * StringUtils.leftPadChar("bat", 1, 'z')  = "bat"
		 * StringUtils.leftPadChar("bat", -1, 'z') = "bat"
		 * </pre>
		 *
		 * @param str 源字符串
		 * @param size 补位后的字符串长度
		 * @param padStr  补位的字符
		 */
		public static function leftPadChar(str:String, size:int, padChar:String):String {
			if (str == null) {
				return null;
			}
			var pads:int = size - str.length;

			if (pads <= 0) {
				return str; // returns original String when possible
			}

			if (pads > PAD_LIMIT) {
				return leftPad(str, size, padChar);
			}
			return padding(pads, padChar).concat(str);
		}

		/**
		 * 在源字符串右侧补充字符,并满足长度为size.如长度小于源代码长度,则直接返回源字符串.
		 * 
		 * <pre>
		 * StringUtils.rightPad(null, *, *)      = null
		 * StringUtils.rightPad("", 3, "z")      = "zzz"
		 * StringUtils.rightPad("bat", 3, "yz")  = "bat"
		 * StringUtils.rightPad("bat", 5, "yz")  = "batyz"
		 * StringUtils.rightPad("bat", 8, "yz")  = "batyzyzy"
		 * StringUtils.rightPad("bat", 1, "yz")  = "bat"
		 * StringUtils.rightPad("bat", -1, "yz") = "bat"
		 * StringUtils.rightPad("bat", 5, null)  = "bat  "
		 * StringUtils.rightPad("bat", 5, "")    = "bat  "
		 * </pre>
		 *
		 * @param str 源字符串
		 * @param size 补位后的字符串长度
		 * @param padStr  补位的字符串
		 */
		public static function rightPad(str:String, size:int, padStr:String):String {
			if (str == null) {
				return null;
			}

			if (isEmpty(padStr)) {
				padStr = " ";
			}
			var padLen:int = padStr.length;
			var strLen:int = str.length;
			var pads:int = size - strLen;

			if (pads <= 0) {
				return str; // returns original String when possible
			}

			if (padLen == 1 && pads <= PAD_LIMIT) {
				return rightPadChar(str, size, padStr.charAt(0));
			}

			if (pads == padLen) {
				return str.concat(padStr);
			} else if (pads < padLen) {
				return str.concat(padStr.substring(0, pads));
			} else {
				var padding:Array = [];
				var padChars:Array = padStr.split("");

				for (var i:int = 0; i < pads; i++) {
					padding[i] = padChars[i % padLen];
				}
				return str.concat(padding.join(""));
			}
		}

		/**
		 * 在源字符串右侧补充字符,并满足长度为size.如长度小于源代码长度,则直接返回源字符串.
		 *
		 * <pre>
		 * StringUtils.rightPadChar(null, *, *)     = null
		 * StringUtils.rightPadChar("", 3, 'z')     = "zzz"
		 * StringUtils.rightPadChar("bat", 3, 'z')  = "bat"
		 * StringUtils.rightPadChar("bat", 5, 'z')  = "batzz"
		 * StringUtils.rightPadChar("bat", 1, 'z')  = "bat"
		 * StringUtils.rightPadChar("bat", -1, 'z') = "bat"
		 * </pre>
		 *
		* @param str 源字符串
		 * @param size 补位后的字符串长度
		 * @param padStr  补位的字符
		 */
		public static function rightPadChar(str:String, size:int, padChar:String):String {
			if (str == null) {
				return null;
			}
			var pads:int = size - str.length;

			if (pads <= 0) {
				return str; // returns original String when possible
			}

			if (pads > PAD_LIMIT) {
				return rightPad(str, size, padChar);
			}
			return str.concat(padding(pads, padChar));
		}

		/**
		 * <p>在字符串右侧重复补充repeat次字符串padChar</p>
		 *
		 * <pre>
		 * StringUtils.padding(0, 'e')  = ""
		 * StringUtils.padding(3, 'e')  = "eee"
		 * StringUtils.padding(-2, 'e') = IndexOutOfBoundsException
		 * </pre>
		 *
		 * @param repeat  补充次数
		 * @param padChar  需要补充的字符串
		 */
		private static function padding(repeat:int, padChar:String):String {
			var buffer:String = '';

			for (var i:int = 0; i < repeat; i++) {
				buffer += padChar;
			}
			return buffer;
		}

		/**
		 * <p>替换字符串中所有pattern字符串为repl字符串.</p>
		 *
		 * <pre>
		 * StringUtils.replace(null, *, *)        = null
		 * StringUtils.replace("", *, *)          = ""
		 * StringUtils.replace("any", null, *)    = "any"
		 * StringUtils.replace("any", *, null)    = "any"
		 * StringUtils.replace("any", "", *)      = "any"
		 * StringUtils.replace("aba", "a", null)  = "aba"
		 * StringUtils.replace("aba", "a", "")    = "b"
		 * StringUtils.replace("aba", "a", "z")   = "zbz"
		 * </pre>
		 *
		 */
		public static function replace(text:String, pattern:String, repl:String):String {
			if (text == null || isEmpty(pattern) || repl == null) {
				return text;
			}
			return text.replace(new RegExp(pattern, 'g'), repl);
		}

		/**
		 * <p>替换字符串中所有pattern字符串为repl字符串,替换次数为max次.</p>
		 *
		 * <pre>
		 * StringUtils.replaceTo(null, *, *, *)         = null
		 * StringUtils.replaceTo("", *, *, *)           = ""
		 * StringUtils.replaceTo("any", null, *, *)     = "any"
		 * StringUtils.replaceTo("any", *, null, *)     = "any"
		 * StringUtils.replaceTo("any", "", *, *)       = "any"
		 * StringUtils.replaceTo("any", *, *, 0)        = "any"
		 * StringUtils.replaceTo("abaa", "a", null, -1) = "abaa"
		 * StringUtils.replaceTo("abaa", "a", "", -1)   = "b"
		 * StringUtils.replaceTo("abaa", "a", "z", 0)   = "abaa"
		 * StringUtils.replaceTo("abaa", "a", "z", 1)   = "zbaa"
		 * StringUtils.replaceTo("abaa", "a", "z", 2)   = "zbza"
		 * StringUtils.replaceTo("abaa", "a", "z", -1)  = "zbzz"
		 * </pre>
		 *
		 * @param text  源字符串
		 * @param repl  被替换的字符串
		 * @param with  替换的目标字符串
		 * @param max  替换的最大次数,-1时替换所有
		 */
		public static function replaceTo(text:String, pattern:String, repl:String, max:int):String {
			if (text == null || isEmpty(pattern) || repl == null || max == 0) {
				return text;
			}

			var buf:String = "";
			var start:int = 0;
			var end:int = 0;

			while ((end = text.indexOf(pattern, start)) != -1) {
				buf += text.substring(start, end) + repl;
				start = end + pattern.length;

				if (--max == 0) {
					break;
				}
			}
			return buf += text.substring(start);
		}

		/**
		 * <p>替换字符串中所有pattern字符串为repl字符串,替换次数为1次.</p>
		 *
		 * <pre>
		 * StringUtils.replaceOnce(null, *, *)        = null
		 * StringUtils.replaceOnce("", *, *)          = ""
		 * StringUtils.replaceOnce("any", null, *)    = "any"
		 * StringUtils.replaceOnce("any", *, null)    = "any"
		 * StringUtils.replaceOnce("any", "", *)      = "any"
		 * StringUtils.replaceOnce("aba", "a", null)  = "aba"
		 * StringUtils.replaceOnce("aba", "a", "")    = "ba"
		 * StringUtils.replaceOnce("aba", "a", "z")   = "zba"
		 * </pre>
		 *
		 * @param text  源字符串
		 * @param repl  被替换的字符串
		 * @param with  替换的目标字符串
		 */
		public static function replaceOnce(text:String, pattern:String, repl:String):String {
			if (text == null || isEmpty(pattern) || repl == null) {
				return text;
			}
			return text.replace(new RegExp(pattern, ''), repl);
		}

		/**
		 * <p>源字符串为空时,默认替换为字符串defaultStr</p>
		 *
		 * <pre>
		 * StringUtils.defaultIfEmpty(null, "NULL")  = "NULL"
		 * StringUtils.defaultIfEmpty("", "NULL")    = "NULL"
		 * StringUtils.defaultIfEmpty("bat", "NULL") = "bat"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param defaultStr  默认字符串
		 */
		public static function defaultIfEmpty(str:String, defaultStr:String):String {
			return isEmpty(str) ? defaultStr : str;
		}

		/**
		 * <p>判断字符串是否为("")或null.</p>
		 *
		 * <pre>
		 * StringUtils.isEmpty(null)      = true
		 * StringUtils.isEmpty("")        = true
		 * StringUtils.isEmpty(" ")       = false
		 * StringUtils.isEmpty("bob")     = false
		 * StringUtils.isEmpty("  bob  ") = false
		 * </pre>
		 *
		 * @return 如果字符串为空或null,返回true;否则返回false.
		 */
		public static function isEmpty(str:String):Boolean {
			if (str == null) {
				return true;
			}
			return str.length == 0;
		}

		/**
		 * <p>判断字符串是否不为("")或null..</p>
		 *
		 * <pre>
		 * StringUtils.isNotEmpty(null)      = false
		 * StringUtils.isNotEmpty("")        = false
		 * StringUtils.isNotEmpty(" ")       = true
		 * StringUtils.isNotEmpty("bob")     = true
		 * StringUtils.isNotEmpty("  bob  ") = true
		 * </pre>
		 *
		 * @return 如果字符串不为空或null,返回true;否则返回false.
		 */
		public static function isNotEmpty(str:String):Boolean {
			return !isEmpty(str);
		}

		/**
		 * <p>判断字符串是否为空格(一个或多个), 空("") 或 null.</p>
		 *
		 * <pre>
		 * StringUtils.isBlank(null)      = true
		 * StringUtils.isBlank("")        = true
		 * StringUtils.isBlank(" ")       = true
		 * StringUtils.isBlank("bob")     = false
		 * StringUtils.isBlank("  bob  ") = false
		 * </pre>
		 *
		 * @return 如果字符串为 null, 空 or 空格(一个或多个)组成,返回true;否则返回false.
		 */
		public static function isBlank(str:String):Boolean {
			return isEmpty(trimToEmpty(str));
		}

		/**
		 * <p>判断字符串是否不为空格(一个或多个), 空("") 或 null.</p>
		 *
		 * <pre>
		 * StringUtils.isNotBlank(null)      = false
		 * StringUtils.isNotBlank("")        = false
		 * StringUtils.isNotBlank(" ")       = false
		 * StringUtils.isNotBlank("bob")     = true
		 * StringUtils.isNotBlank("  bob  ") = true
		 * </pre>
		 *
		 * 如果字符串不为 null, 空 或 空格(一个或多个)组成,返回true;否则返回false.
		 */
		public static function isNotBlank(str:String):Boolean {
			return !isBlank(str);
		}

		/**
		 * <p>如果字符串trim后为空,null或多个空格.则返回null.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.trimToNull(null)          = null
		 * StringUtils.trimToNull("")            = null
		 * StringUtils.trimToNull("     ")       = null
		 * StringUtils.trimToNull("abc")         = "abc"
		 * StringUtils.trimToNull("    abc    ") = "abc"
		 * </pre>
		 *
		 * @return 如果字符串trim后为空或null.则返回null.否则返回源字符串.
		 */
		public static function trimToNull(str:String):String {
			var ts:String = trim(str);
			return isEmpty(ts) ? null : ts;
		}

		/**
		 * <p>如果字符串trim后为空,null或多个空格.则返回空</p>.
		 *
		 * <pre>
		 * StringUtils.trimToEmpty(null)          = ""
		 * StringUtils.trimToEmpty("")            = ""
		 * StringUtils.trimToEmpty("     ")       = ""
		 * StringUtils.trimToEmpty("abc")         = "abc"
		 * StringUtils.trimToEmpty("    abc    ") = "abc"
		 * </pre>
		 *
		 * @return 如果字符串trim后为空或null.则返回空.否则返回源字符串.
		 */
		public static function trimToEmpty(str:String):String {
			return str == null ? EMPTY : trim(str);
		}

		/**
		 * <p>将字符串的第一个字符转变为大写并返回.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.capitalize(null)  = null
		 * StringUtils.capitalize("")    = ""
		 * StringUtils.capitalize("cat") = "Cat"
		 * StringUtils.capitalize("cAt") = "CAt"
		 * </pre>
		 * @param str
		 */
		public static function capitalize(str:String):String {
			if (isEmpty(str)) {
				return str;
			}
			return str.charAt(0).toUpperCase() + str.substring(1);
		}

		/**
		 * <p>将字符串的第一个字符转变为小写并返回.</p>
		 *
		 * <pre>
		 * StringUtils.uncapitalize(null)  = null
		 * StringUtils.uncapitalize("")    = ""
		 * StringUtils.uncapitalize("Cat") = "cat"
		 * StringUtils.uncapitalize("CAT") = "cAT"
		 * </pre>
		 *
		 * @param str  
		 */
		public static function uncapitalize(str:String):String {
			if (isEmpty(str)) {
				return str;
			}
			return str.charAt(0).toLowerCase() + str.substring(1);
		}

		/**
		 * <p>将字符串的每个单词的第一个字符转变为大写并返回.</p>
		 *
		 * <pre>
		 * StringUtils.titleize(null)  = null
		 * StringUtils.titleize("")    = ""
		 * StringUtils.titleize("man from the boondocks") = "Man From The Boondocks"
		 * StringUtils.titleize("man from THE bOOndocks") = "Man From The Boondocks"
		 * </pre>
		 *
		 * @param str  the String to uncapitalize, may be null
		 * @return the uncapitalized String, <code>null</code> if null String input
		 * @see #capitalize(String)
		 */
		public static function titleize(str:String):String {
			if (isEmpty(str)) {
				return str;
			}
			var words:Array = str.toLowerCase().split(' ');

			for (var i:int = 0; i < words.length; i++) {
				words[i] = capitalize(words[i]);
			}
			return words.join(' ');
		}

		/**
		 * <p>获得源字符串中第一个符合separator字符串后面的字符串.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.substringAfter(null, *)      = null
		 * StringUtils.substringAfter("", *)        = ""
		 * StringUtils.substringAfter(*, null)      = ""
		 * StringUtils.substringAfter("abc", "a")   = "bc"
		 * StringUtils.substringAfter("abcba", "b") = "cba"
		 * StringUtils.substringAfter("abc", "c")   = ""
		 * StringUtils.substringAfter("abc", "d")   = ""
		 * StringUtils.substringAfter("abc", "")    = "abc"
		 * </pre>
		 *
		 */
		public static function substringAfter(str:String, separator:String):String {
			if (isEmpty(str)) {
				return str;
			}

			if (separator == null) {
				return EMPTY;
			}
			var pos:int = str.indexOf(separator);

			if (pos == INDEX_NOT_FOUND) {
				return EMPTY;
			}
			return str.substring(pos + separator.length);
		}

		/**
		 * <p>获得源字符串中最后一个符合separator字符串后面的字符串.</p>
		 *
		 * <pre>
		 * StringUtils.substringAfterLast(null, *)      = null
		 * StringUtils.substringAfterLast("", *)        = ""
		 * StringUtils.substringAfterLast(*, "")        = ""
		 * StringUtils.substringAfterLast(*, null)      = ""
		 * StringUtils.substringAfterLast("abc", "a")   = "bc"
		 * StringUtils.substringAfterLast("abcba", "b") = "a"
		 * StringUtils.substringAfterLast("abc", "c")   = ""
		 * StringUtils.substringAfterLast("a", "a")     = ""
		 * StringUtils.substringAfterLast("a", "z")     = ""
		 * </pre>
		 *
		 */
		public static function substringAfterLast(str:String, separator:String):String {
			if (isEmpty(str)) {
				return str;
			}

			if (isEmpty(separator)) {
				return EMPTY;
			}
			var pos:int = str.lastIndexOf(separator);

			if (pos == INDEX_NOT_FOUND || pos == (str.length - separator.length)) {
				return EMPTY;
			}
			return str.substring(pos + separator.length);
		}

		/**
		 * <p>获得源字符串中第一个符合separator字符串前面面的字符串.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.substringBefore(null, *)      = null
		 * StringUtils.substringBefore("", *)        = ""
		 * StringUtils.substringBefore("abc", "a")   = ""
		 * StringUtils.substringBefore("abcba", "b") = "a"
		 * StringUtils.substringBefore("abc", "c")   = "ab"
		 * StringUtils.substringBefore("abc", "d")   = "abc"
		 * StringUtils.substringBefore("abc", "")    = ""
		 * StringUtils.substringBefore("abc", null)  = "abc"
		 * </pre>
		 *
		 */
		public static function substringBefore(str:String, separator:String):String {
			if (isEmpty(str) || separator == null) {
				return str;
			}

			if (separator.length == 0) {
				return EMPTY;
			}
			var pos:int = str.indexOf(separator);

			if (pos == INDEX_NOT_FOUND) {
				return str;
			}
			return str.substring(0, pos);
		}

		/**
		 * <p>获得源字符串中最后一个符合separator字符串前面的字符串.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.substringBeforeLast(null, *)      = null
		 * StringUtils.substringBeforeLast("", *)        = ""
		 * StringUtils.substringBeforeLast("abcba", "b") = "abc"
		 * StringUtils.substringBeforeLast("abc", "c")   = "ab"
		 * StringUtils.substringBeforeLast("a", "a")     = ""
		 * StringUtils.substringBeforeLast("a", "z")     = "a"
		 * StringUtils.substringBeforeLast("a", null)    = "a"
		 * StringUtils.substringBeforeLast("a", "")      = "a"
		 * </pre>
		 *
		 */
		public static function substringBeforeLast(str:String, separator:String):String {
			if (isEmpty(str) || isEmpty(separator)) {
				return str;
			}
			var pos:int = str.lastIndexOf(separator);

			if (pos == INDEX_NOT_FOUND) {
				return str;
			}
			return str.substring(0, pos);
		}

		/**
		 * <p>获得源字符串中open字符串和close字符串中间的字符串.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.substringBetween(null, *, *)          = null
		 * StringUtils.substringBetween("", "", "")          = ""
		 * StringUtils.substringBetween("", "", "tag")       = null
		 * StringUtils.substringBetween("", "tag", "tag")    = null
		 * StringUtils.substringBetween("yabcz", null, null) = null
		 * StringUtils.substringBetween("yabcz", "", "")     = ""
		 * StringUtils.substringBetween("yabcz", "y", "z")   = "abc"
		 * StringUtils.substringBetween("yabczyabcz", "y", "z")   = "abc"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param open 开始字符串
		 * @param close  结束字符串
		 * @return 目标字符串
		 */
		public static function substringBetween(str:String, open:String, close:String):String {
			if (str == null || open == null || close == null) {
				return null;
			}
			var start:int = str.indexOf(open);

			if (start != INDEX_NOT_FOUND) {
				var end:int = str.indexOf(close, start + open.length);

				if (end != INDEX_NOT_FOUND) {
					return str.substring(start + open.length, end);
				}
			}
			return null;
		}

		/**
		 * <p>去除源字符串所有的stripChars字符(以单个字符计).</p>
		 *
		 *
		 * <pre>
		 * StringUtils.strip(null, *)          = null
		 * StringUtils.strip("", *)            = ""
		 * StringUtils.strip("abc", null)      = "abc"
		 * StringUtils.strip("  abc", null)    = "abc"
		 * StringUtils.strip("abc  ", null)    = "abc"
		 * StringUtils.strip(" abc ", null)    = "abc"
		 * StringUtils.strip("  abcyx", "xyz") = "  abc"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param stripChars  需要被去穿的字符
		 * @return 去除后的字符
		 */
		public static function strip(str:String, stripChars:String):String {
			if (isEmpty(str)) {
				return str;
			}
			return stripEnd(stripStart(str, stripChars), stripChars);
		}

		/**
		 * <p>去除源字符串中开始字符为stripChars字符(以单个字符计)的所有字符.</p>
		 *
		 * <pre>
		 * StringUtils.stripStart(null, *)          = null
		 * StringUtils.stripStart("", *)            = ""
		 * StringUtils.stripStart("abc", "")        = "abc"
		 * StringUtils.stripStart("abc", null)      = "abc"
		 * StringUtils.stripStart("  abc", null)    = "abc"
		 * StringUtils.stripStart("abc  ", null)    = "abc  "
		 * StringUtils.stripStart(" abc ", null)    = "abc "
		 * StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param stripChars  需要被去穿的字符
		 * @return 去除后的字符
		 */
		public static function stripStart(str:String, stripChars:String):String {
			if (isEmpty(str)) {
				return str;
			}
			var p:RegExp = new RegExp('^[' + (stripChars != null ? stripChars : ' ') + ']*', '');
			return str.replace(p, '');
		}

		/**
		 * <p>去除源字符串中结束字符为stripChars字符(以单个字符计)的所有字符.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.stripEnd(null, *)          = null
		 * StringUtils.stripEnd("", *)            = ""
		 * StringUtils.stripEnd("abc", "")        = "abc"
		 * StringUtils.stripEnd("abc", null)      = "abc"
		 * StringUtils.stripEnd("  abc", null)    = "  abc"
		 * StringUtils.stripEnd("abc  ", null)    = "abc"
		 * StringUtils.stripEnd(" abc ", null)    = " abc"
		 * StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param stripChars  需要被去穿的字符
		 * @return 去除后的字符
		 */
		public static function stripEnd(str:String, stripChars:String):String {
			if (isEmpty(str)) {
				return str;
			}
			var p:RegExp = new RegExp('[' + (stripChars != null ? stripChars : ' ') + ']*$', '');
			return str.replace(p, '');
		}

		/**
		 * <p>将字符串转变为固定长度,并省略后面的字符,以"..."代替.</p>
		 *
		 * <pre>
		 * StringUtils.abbreviate(null, *, *)                = null
		 * StringUtils.abbreviate("", 0, 4)                  = ""
		 * StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..."
		 * StringUtils.abbreviate("abcdefghijklmno", 0, 10)  = "abcdefg..."
		 * StringUtils.abbreviate("abcdefghijklmno", 1, 10)  = "abcdefg..."
		 * StringUtils.abbreviate("abcdefghijklmno", 4, 10)  = "abcdefg..."
		 * StringUtils.abbreviate("abcdefghijklmno", 5, 10)  = "...fghi..."
		 * StringUtils.abbreviate("abcdefghijklmno", 6, 10)  = "...ghij..."
		 * StringUtils.abbreviate("abcdefghijklmno", 8, 10)  = "...ijklmno"
		 * StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno"
		 * StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno"
		 * StringUtils.abbreviate("abcdefghij", 0, 3)        = IllegalArgumentException
		 * StringUtils.abbreviate("abcdefghij", 5, 6)        = IllegalArgumentException
		 * </pre>
		 *
		 */
		public static function abbreviate(str:String, offset:int, maxWidth:int):String {
			if (str == null) {
				return str;
			}

			if (maxWidth < 4) {
				throw new IllegalArgumentError("Minimum abbreviation width is 4");
			}

			if (str.length <= maxWidth) {
				return str;
			}

			if (offset > str.length) {
				offset = str.length;
			}

			if ((str.length - offset) < (maxWidth - 3)) {
				offset = str.length - (maxWidth - 3);
			}

			if (offset <= 4) {
				return str.substring(0, maxWidth - 3) + "...";
			}

			if (maxWidth < 7) {
				throw new IllegalArgumentError("Minimum abbreviation width with offset is 7");
			}

			if ((offset + (maxWidth - 3)) < str.length) {
				return "..." + abbreviate(str.substring(offset), 0, maxWidth - 3);
			}
			return "..." + str.substring(str.length - (maxWidth - 3));
		}

		/**
		 * <p>从固定位置开始,在源字符串中查找固定字符串,并返回其开始位置.</p>
		 *
		 * <pre>
		 * StringUtils.ordinalIndexOf(null, *, *)          = -1
		 * StringUtils.ordinalIndexOf(*, null, *)          = -1
		 * StringUtils.ordinalIndexOf("", "", *)           = 0
		 * StringUtils.ordinalIndexOf("aabaabaa", "a", 1)  = 0
		 * StringUtils.ordinalIndexOf("aabaabaa", "a", 2)  = 1
		 * StringUtils.ordinalIndexOf("aabaabaa", "b", 1)  = 2
		 * StringUtils.ordinalIndexOf("aabaabaa", "b", 2)  = 5
		 * StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1
		 * StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4
		 * StringUtils.ordinalIndexOf("aabaabaa", "", 1)   = 0
		 * StringUtils.ordinalIndexOf("aabaabaa", "", 2)   = 0
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param searchStr  查找的字符串
		 * @param ordinal  开始查找位置
		 * @return 查找到的字符串的位置.找不到则返回-1.
		 */
		public static function ordinalIndexOf(str:String, searchStr:String, ordinal:int):int {
			if (str == null || searchStr == null || ordinal <= 0) {
				return INDEX_NOT_FOUND;
			}

			if (searchStr.length == 0) {
				return 0;
			}
			var found:int = 0;
			var index:int = INDEX_NOT_FOUND;

			do {
				index = str.indexOf(searchStr, index + 1);

				if (index < 0) {
					return index;
				}
				found++;
			} while (found < ordinal);
			return index;
		}

		/**
		 * <p>h获得sub字符串在源字符串str中出现的次数.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.countMatches(null, *)       = 0
		 * StringUtils.countMatches("", *)         = 0
		 * StringUtils.countMatches("abba", null)  = 0
		 * StringUtils.countMatches("abba", "")    = 0
		 * StringUtils.countMatches("abba", "a")   = 2
		 * StringUtils.countMatches("abba", "ab")  = 1
		 * StringUtils.countMatches("abba", "xxx") = 0
		 * </pre>
		 *
		 */
		public static function countMatches(str:String, sub:String):int {
			if (isEmpty(str) || isEmpty(sub)) {
				return 0;
			}
			return str.match(new RegExp('(' + sub + ')', 'g')).length;
		}

		/**
		 * <p>判断源字符串中是否存在searchStr字符串.</p>
		 *
		 * <pre>
		 * StringUtils.contains(null, *)     = false
		 * StringUtils.contains(*, null)     = false
		 * StringUtils.contains("", "")      = true
		 * StringUtils.contains("abc", "")   = true
		 * StringUtils.contains("abc", "a")  = true
		 * StringUtils.contains("abc", "z")  = false
		 * </pre>
		 *
		 * @return 存在则返回true;否则返回false.
		 */
		public static function contains(str:String, searchStr:String):Boolean {
			if (str == null || searchStr == null) {
				return false;
			}
			return new RegExp('(' + searchStr + ')', 'g').test(str);
		}

		/**
		 * <p>判断源字符串中是否不存在searchStr字符串.</p>
		 *
		 * <pre>
		 * StringUtils.containsNone(null, *)       = true
		 * StringUtils.containsNone(*, null)       = true
		 * StringUtils.containsNone("", *)         = true
		 * StringUtils.containsNone("ab", "")      = true
		 * StringUtils.containsNone("abab", "xyz") = true
		 * StringUtils.containsNone("ab1", "xyz")  = true
		 * StringUtils.containsNone("abz", "xyz")  = false
		 * </pre>
		 *
		 * @return 不存在则返回true;否则返回false.
		 */
		public static function containsNone(str:String, invalidChars:String):Boolean {
			if (isEmpty(str) || invalidChars == null) {
				return true;
			}
			return new RegExp('^[^' + invalidChars + ']*$', '').test(str);
		}

		/**
		 * <p>判断源字符串中是否searchStr字符串出出现一次.</p>
		 *
		 * <pre>
		 * StringUtils.containsOnly(null, *)       = false
		 * StringUtils.containsOnly(*, null)       = false
		 * StringUtils.containsOnly("", *)         = true
		 * StringUtils.containsOnly("ab", "")      = false
		 * StringUtils.containsOnly("abab", "abc") = true
		 * StringUtils.containsOnly("ab1", "abc")  = false
		 * StringUtils.containsOnly("abz", "abc")  = false
		 * </pre>
		 *
		 * @return 出现一次返回true;否则返回false.
		 */
		public static function containsOnly(str:String, validChars:String):Boolean {
			if (str == null || isEmpty(validChars)) {
				return false;
			}

			if (str.length == 0) {
				return true;
			}
			return new RegExp('^[' + validChars + ']*$', 'g').test(str);
		}

		/**
		 * <p>按照给定的字符串,判断源字符串中是否存在(searchChars以单个字符计),并返回存在的第一个位置.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.indexOfAny(null, *)            = -1
		 * StringUtils.indexOfAny("", *)              = -1
		 * StringUtils.indexOfAny(*, null)            = -1
		 * StringUtils.indexOfAny(*, "")              = -1
		 * StringUtils.indexOfAny("zzabyycdxx", "za") = 0
		 * StringUtils.indexOfAny("zzabyycdxx", "by") = 3
		 * StringUtils.indexOfAny("aba","z")          = -1
		 * </pre>
		 *
		 */
		public static function indexOfAny(str:String, searchChars:String):int {
			if (isEmpty(str) || isEmpty(searchChars)) {
				return INDEX_NOT_FOUND;
			}
			return str.search(new RegExp('[' + searchChars + ']', ''));
		}

		/**
		 * <p>按照给定的字符串,判断源字符串中不存在(searchChars以单个字符计),并返回不存在的第一个位置.</p>
		 *
		 * <pre>
		 * StringUtils.indexOfAnyBut(null, *)            = -1
		 * StringUtils.indexOfAnyBut("", *)              = -1
		 * StringUtils.indexOfAnyBut(*, null)            = -1
		 * StringUtils.indexOfAnyBut(*, "")              = -1
		 * StringUtils.indexOfAnyBut("zzabyycdxx", "za") = 3
		 * StringUtils.indexOfAnyBut("aba","ab")         = -1
		 * </pre>
		 *
		 */
		public static function indexOfAnyBut(str:String, searchChars:String):int {
			if (isEmpty(str) || isEmpty(searchChars)) {
				return INDEX_NOT_FOUND;
			}
			return str.search(new RegExp('[^' + searchChars + ']', ''));
		}

		/**
		 * <p>比较两个字符串,返回第二个字符串从第一个不同位置起后面的字符串.</p>
		 *
		 * <p>例如,
		 * <code>difference("i am a machine", "i am a robot") -> "robot"</code>.</p>
		 *
		 * <pre>
		 * StringUtils.difference(null, null) = null
		 * StringUtils.difference("", "") = ""
		 * StringUtils.difference("", "abc") = "abc"
		 * StringUtils.difference("abc", "") = ""
		 * StringUtils.difference("abc", "abc") = ""
		 * StringUtils.difference("ab", "abxyz") = "xyz"
		 * StringUtils.difference("abcde", "abxyz") = "xyz"
		 * StringUtils.difference("abcde", "xyz") = "xyz"
		 * </pre>
		 *
		 */
		public static function difference(str1:String, str2:String):String {
			if (str1 == null) {
				return str2;
			}

			if (str2 == null) {
				return str1;
			}
			var at:int = indexOfDifference(str1, str2);

			if (at == -1) {
				return EMPTY;
			}
			return str2.substring(at);
		}

		/**
		 * <p>比较两个字符串,并返回其第一个不同字符的位置.</p>
		 *
		 * <p>例如,
		 * <code>indexOfDifference("i am a machine", "i am a robot") -> 7</code></p>
		 *
		 * <pre>
		 * StringUtils.indexOfDifference(null, null) = -1
		 * StringUtils.indexOfDifference("", "") = -1
		 * StringUtils.indexOfDifference("", "abc") = 0
		 * StringUtils.indexOfDifference("abc", "") = 0
		 * StringUtils.indexOfDifference("abc", "abc") = -1
		 * StringUtils.indexOfDifference("ab", "abxyz") = 2
		 * StringUtils.indexOfDifference("abcde", "abxyz") = 2
		 * StringUtils.indexOfDifference("abcde", "xyz") = 0
		 * </pre>
		 *
		 */
		public static function indexOfDifference(str1:String, str2:String):int {
			if (str1 == str2) {
				return INDEX_NOT_FOUND;
			}

			if (isEmpty(str1) || isEmpty(str2)) {
				return 0;
			}
			var i:int;

			for (i = 0; i < str1.length && i < str2.length; ++i) {
				if (str1.charAt(i) != str2.charAt(i)) {
					break;
				}
			}

			if (i < str2.length || i < str1.length) {
				return i;
			}
			return INDEX_NOT_FOUND;
		}

		/**
		 * <p>判断两个字符串是否相等(区分大小写).</p>
		 *
		 * <pre>
		 * StringUtils.equals(null, null)   = true
		 * StringUtils.equals(null, "abc")  = false
		 * StringUtils.equals("abc", null)  = false
		 * StringUtils.equals("abc", "abc") = true
		 * StringUtils.equals("abc", "ABC") = false
		 * </pre>
		 *
		 */
		public static function equals(str1:String, str2:String):Boolean {
			return (str1 === str2);
		}

		/**
		 * <p>判断两个字符串是否相等(不区分大小写).</p>
		 *
		 *
		 * <pre>
		 * StringUtils.equalsIgnoreCase(null, null)   = true
		 * StringUtils.equalsIgnoreCase(null, "abc")  = false
		 * StringUtils.equalsIgnoreCase("abc", null)  = false
		 * StringUtils.equalsIgnoreCase("abc", "abc") = true
		 * StringUtils.equalsIgnoreCase("abc", "ABC") = true
		 * </pre>
		 *
		 */
		public static function equalsIgnoreCase(str1:String, str2:String):Boolean {
			if (str1 == null && str2 == null) {
				return true;
			} else if (str1 == null || str2 == null) {
				return false;
			}
			return equals(str1.toLowerCase(), str2.toLowerCase());
		}

		/**
		 * <p>判断字符串中每个字符是否都是字母字符.</p>
		 *
		 * <pre>
		 * StringUtils.isAlpha(null)   = false
		 * StringUtils.isAlpha("")     = true
		 * StringUtils.isAlpha("  ")   = false
		 * StringUtils.isAlpha("abc")  = true
		 * StringUtils.isAlpha("ab2c") = false
		 * StringUtils.isAlpha("ab-c") = false
		 * </pre>
		 *
		 */
		public static function isAlpha(str:String):Boolean {
			return testString(str, /^[a-zA-Z]*$/);
		}

		/**
		 * <p>判断字符串中中每个字符都是字母字符或空格(' ').</p>
		 *
		 *
		 * <pre>
		 * StringUtils.isAlphaSpace(null)   = false
		 * StringUtils.isAlphaSpace("")     = true
		 * StringUtils.isAlphaSpace("  ")   = true
		 * StringUtils.isAlphaSpace("abc")  = true
		 * StringUtils.isAlphaSpace("ab c") = true
		 * StringUtils.isAlphaSpace("ab2c") = false
		 * StringUtils.isAlphaSpace("ab-c") = false
		 * </pre>
		 *
		 */
		public static function isAlphaSpace(str:String):Boolean {
			return testString(str, /^[a-zA-Z\s]*$/);
		}

		/**
		 * <p>判断字符串中的每个字符都是字母字符或数字.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.isAlphanumeric(null)   = false
		 * StringUtils.isAlphanumeric("")     = true
		 * StringUtils.isAlphanumeric("  ")   = false
		 * StringUtils.isAlphanumeric("abc")  = true
		 * StringUtils.isAlphanumeric("ab c") = false
		 * StringUtils.isAlphanumeric("ab2c") = true
		 * StringUtils.isAlphanumeric("ab-c") = false
		 * </pre>
		 *
		 */
		public static function isAlphanumeric(str:String):Boolean {
			return testString(str, /^[a-zA-Z0-9]*$/);
		}

		/**
		 * <p>判断字符串中的每个字符都是字母字符,数字或空格(' ').</p>
		 *
		 *
		 * <pre>
		 * StringUtils.isAlphanumericSpace(null)   = false
		 * StringUtils.isAlphanumericSpace("")     = true
		 * StringUtils.isAlphanumericSpace("  ")   = true
		 * StringUtils.isAlphanumericSpace("abc")  = true
		 * StringUtils.isAlphanumericSpace("ab c") = true
		 * StringUtils.isAlphanumericSpace("ab2c") = true
		 * StringUtils.isAlphanumericSpace("ab-c") = false
		 * </pre>
		 *
		 */
		public static function isAlphanumericSpace(str:String):Boolean {
			return testString(str, /^[a-zA-Z0-9\s]*$/);
		}

		/**
		 * <p>判断字符串是否为数字.</p>
		 *
		 * <p><code>null</code> will return <code>false</code>.
		 * An empty String("") will return <code>true</code>.</p>
		 *
		 * <pre>
		 * StringUtils.isNumeric(null)   = false
		 * StringUtils.isNumeric("")     = true
		 * StringUtils.isNumeric("  ")   = false
		 * StringUtils.isNumeric("123")  = true
		 * StringUtils.isNumeric("12 3") = false
		 * StringUtils.isNumeric("ab2c") = false
		 * StringUtils.isNumeric("12-3") = false
		 * StringUtils.isNumeric("12.3") = false
		 * </pre>
		 *
		 */
		public static function isNumeric(str:String):Boolean {
			return testString(str, /^[0-9]*$/);
		}

		/**
		 * <p>判断字符串是否为数字或空格.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.isNumericSpace(null)   = false
		 * StringUtils.isNumericSpace("")     = true
		 * StringUtils.isNumericSpace("  ")   = true
		 * StringUtils.isNumericSpace("123")  = true
		 * StringUtils.isNumericSpace("12 3") = true
		 * StringUtils.isNumericSpace("ab2c") = false
		 * StringUtils.isNumericSpace("12-3") = false
		 * StringUtils.isNumericSpace("12.3") = false
		 * </pre>
		 *
		 */
		public static function isNumericSpace(str:String):Boolean {
			return testString(str, /^[0-9\s]*$/);
		}

		/**
		 * <p>判断字符串是否为空格组成.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.isWhitespace(null)   = false
		 * StringUtils.isWhitespace("")     = true
		 * StringUtils.isWhitespace("  ")   = true
		 * StringUtils.isWhitespace("abc")  = false
		 * StringUtils.isWhitespace("ab2c") = false
		 * StringUtils.isWhitespace("ab-c") = false
		 * </pre>
		 *
		 */
		public static function isWhitespace(str:String):Boolean {
			return testString(str, /^[\s]*$/);
		}

		private static function testString(str:String, pattern:RegExp):Boolean {
			return str != null && pattern.test(str);
		}

		/**
		 * <p>替换源字符串中的某一部分字符串为目标字符串.</p>
		 *
		 * <pre>
		 * StringUtils.overlay(null, *, *, *)            = null
		 * StringUtils.overlay("", "abc", 0, 0)          = "abc"
		 * StringUtils.overlay("abcdef", null, 2, 4)     = "abef"
		 * StringUtils.overlay("abcdef", "", 2, 4)       = "abef"
		 * StringUtils.overlay("abcdef", "", 4, 2)       = "abef"
		 * StringUtils.overlay("abcdef", "zzzz", 2, 4)   = "abzzzzef"
		 * StringUtils.overlay("abcdef", "zzzz", 4, 2)   = "abzzzzef"
		 * StringUtils.overlay("abcdef", "zzzz", -1, 4)  = "zzzzef"
		 * StringUtils.overlay("abcdef", "zzzz", 2, 8)   = "abzzzz"
		 * StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef"
		 * StringUtils.overlay("abcdef", "zzzz", 8, 10)  = "abcdefzzzz"
		 * </pre>
		 *
		 * @param str  源字符串
		 * @param overlay  替换目标字符串
		 * @param start  替换开始替换位置
		 * @param end    替换结束位置
		 * @return 
		 */
		public static function overlay(str:String, overlay:String, start:int, end:int):String {
			if (str == null) {
				return null;
			}

			if (overlay == null) {
				overlay = EMPTY;
			}
			var len:int = str.length;

			if (start < 0) {
				start = 0;
			}

			if (start > len) {
				start = len;
			}

			if (end < 0) {
				end = 0;
			}

			if (end > len) {
				end = len;
			}

			if (start > end) {
				var temp:int = start;
				start = end;
				end = temp;
			}
			return str.substring(0, start).concat(overlay).concat(str.substring(end));
		}

		/**
		 * <p>去除字符串中所有特定的当个字符(remove中的单个字符).</p>
		 *
		 * <pre>
		 * StringUtils.remove(null, *)        = null
		 * StringUtils.remove("", *)          = ""
		 * StringUtils.remove(*, null)        = *
		 * StringUtils.remove(*, "")          = *
		 * StringUtils.remove("queued", "ue") = "qd"
		 * StringUtils.remove("queued", "zz") = "queued"
		 * </pre>
		 *
		 */
		public static function remove(str:String, remove:String):String {
			return safeRemove(str, new RegExp(remove, 'g'));
		}

		/**
		 * <p>如果源字符串以remove结尾,则去除该字符.</p>
		 *
		 * <pre>
		 * StringUtils.removeEnd(null, *)      = null
		 * StringUtils.removeEnd("", *)        = ""
		 * StringUtils.removeEnd(*, null)      = *
		 * StringUtils.removeEnd("www.domain.com", ".com")   = "www.domain"
		 * StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
		 * StringUtils.removeEnd("abc", "")    = "abc"
		 * </pre>
		 *
		 */
		public static function removeEnd(str:String, remove:String):String {
			return safeRemove(str, new RegExp(remove + '$', ''));
		}

		/**
		 * <p>如果源字符串以remove开始,则去除该字符.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.removeStart(null, *)      = null
		 * StringUtils.removeStart("", *)        = ""
		 * StringUtils.removeStart(*, null)      = *
		 * StringUtils.removeStart("www.domain.com", "www.")   = "domain.com"
		 * StringUtils.removeStart("domain.com", "www.")       = "domain.com"
		 * StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
		 * StringUtils.removeStart("abc", "")    = "abc"
		 * </pre>
		 *
		 */
		public static function removeStart(str:String, remove:String):String {
			return safeRemove(str, new RegExp('^' + remove, ''));
		}

		private static function safeRemove(str:String, pattern:RegExp):String {
			if (isEmpty(str)) {
				return str;
			}
			return str.replace(pattern, '');
		}

		/**
		 * <p>判断字符串是否以特定字符结尾.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.endsWith(null, *)	 				= false
		 * StringUtils.endsWith(null, null) 				= false
		 * StringUtils.endsWith(*, null)	   				= false
		 * StringUtils.endsWith("www.domain.com", "com") = true
		 * </pre>
		 *
		 */
		public static function endsWith(str:String, end:String):Boolean {
			return testString(str, new RegExp(end + '$', ''));
		}

		/**
		 * <p>判断字符串是否以特定字符开始.</p>
		 *
		 *
		 * <pre>
		 * StringUtils.startsWith(null, *)	 				= false
		 * StringUtils.startsWith(null, null) 				= false
		 * StringUtils.startsWith(*, null)	   				= false
		 * StringUtils.startsWith("www.domain.com", "www.")	= true
		 * </pre>
		 *
		 */
		public static function startsWith(str:String, start:String):Boolean {
			return testString(str, new RegExp('^' + start, ''));
		}

		/**
		 * <p>判断两个字符串是否相等(不区分大小写).</p>
		 *
		 * @return  返回不相同位置的下标
		 */
		public static function compareToIgnoreCase(str1:String, str2:String):int {
			if (str1 == null) {
				str1 = "";
			}

			if (str2 == null) {
				str2 = "";
			}

			return compareTo(str1.toLowerCase(), str2.toLowerCase());
		}

		/**
		 * 判断两个字符创是否相等(区分大小写).
		 *
		 * @return  返回不相同位置的下标
		 */
		public static function compareTo(str1:String, str2:String):int {
			if (str1 == null) {
				str1 = "";
			}

			if (str2 == null) {
				str2 = "";
			}
			return str1.localeCompare(str2);
		}

		/**
		 * 在特定位置上加上特定的字符 
		 * @param string
		 * @param value
		 * @param position
		 * @return 
		 * 
		 */		
		public static function addAt(string:String, value:*, position:int):String {
			if (position > string.length) {
				position = string.length;
			}
			var firstPart:String = string.substring(0, position);
			var secondPart:String = string.substring(position, string.length);
			return (firstPart + value + secondPart);
		}

		/**
		 * 将源字符串中的特定位置的字符串替换为特定字符 
		 * @param string
		 * @param value
		 * @param beginIndex
		 * @param endIndex
		 * @return 
		 * 
		 */		
		public static function replaceAt(string:String, value:*, beginIndex:int, endIndex:int):String {
			beginIndex = Math.max(beginIndex, 0);
			endIndex = Math.min(endIndex, string.length);
			var firstPart:String = string.substr(0, beginIndex);
			var secondPart:String = string.substr(endIndex, string.length);
			return (firstPart + value + secondPart);
		}

		/**
		 * 去除源字符串中的特定位置的字符串.
		 * @param string
		 * @param beginIndex
		 * @param endIndex
		 * @return 
		 * 
		 */		
		public static function removeAt(string:String, beginIndex:int, endIndex:int):String {
			return BOPStringUtils.replaceAt(string, "", beginIndex, endIndex);
		}

		/**
		 * 将源字符串中的连续多个换行替换为一个换行. 
		 * @param string
		 * @return 
		 * 
		 */		
		public static function fixNewlines(string:String):String {
			return string.replace(/\r\n/gm, "\n");
		}

		/**
		 * 判断字符串中是否存在真实字符. 
		 * @param string
		 * @return 
		 * 
		 */		
		public static function hasText(string:String):Boolean {
			if (!string)
				return false;
			return (BOPStringUtils.trim(string).length > 0);
		}

		/**
		 * 去除字符串开始的空格.
		 *
		 *
		 * @param string the string to trim
		 * @return the trimmed string
		 */
		public static function leftTrim(string:String):String {
			return leftTrimForChars(string, "\n\t\n ");
		}

		/**
		 * 去除字符串结尾的空格.
		 *
		 * <p>Characters that are removed: spaces {@code " "}, line forwards {@code "\n"}
		 * and extended line forwarding {@code "\t\n"}.
		 *
		 * @param string the string to trim
		 * @return the trimmed string
		 */
		public static function rightTrim(string:String):String {
			return rightTrimForChars(string, "\n\t\n ");
		}

		/**
		 * 去除源字符串中开始的所有的给定字符(可多个).
		 *
		 *
		 * <p>例如:
		 * <code>
		 *   trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // oynkeym
		 *   trace(StringUtil.rightTrimForChars("monkey", "mo")); // nkey
		 *   trace(StringUtil.rightTrimForChars("monkey", "om")); // nkey
		 * </code>
		 *
		 */
		public static function leftTrimForChars(string:String, chars:String):String {
			var from:Number = 0;
			var to:Number = string.length;

			while (from < to && chars.indexOf(string.charAt(from)) >= 0) {
				from++;
			}
			return (from > 0 ? string.substr(from, to) : string);
		}

		/**
		 * 去除源字符串中结尾的所有的给定字符(可多个).
		 *
		 *
		 * <p>例如:
		 * <code>
		 *   trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // ymoynke
		 *   trace(StringUtil.rightTrimForChars("monkey***", "*y")); // monke
		 *   trace(StringUtil.rightTrimForChars("monke*y**", "*y")); // monke
		 * </code>
		 *
		 */
		public static function rightTrimForChars(string:String, chars:String):String {
			var from:Number = 0;
			var to:Number = string.length - 1;

			while (from < to && chars.indexOf(string.charAt(to)) >= 0) {
				to--;
			}
			return (to >= 0 ? string.substr(from, to + 1) : string);
		}

		/**
		 * <p>去除源字符串中开始的所有的给定字符(单个).
		 *
		 * 
		 * <code>
		 *   trace(StringUtil.leftTrimForChar("yyyymonkeyyyy", "y"); // monkeyyyy
		 * </code>
		 *
		 */
		public static function leftTrimForChar(string:String, char:String):String {
			if (char.length != 1) {
				throw new IllegalArgumentError("添加字符 [" + char + "] 必须为一个字符.");
			}
			return leftTrimForChars(string, char);
		}

		/**
		 * 去除源字符串中结尾的所有的给定字符(单个).
		 *
		 * <p>例如:
		 * <code>
		 *   trace(StringUtil.rightTrimForChar("yyyymonkeyyyy", "y"); // yyyymonke
		 * </code>
		 *
		 */
		public static function rightTrimForChar(string:String, char:String):String {
			if (char.length != 1) {
				throw new IllegalArgumentError("添加字符 [" + char + "] 必须为一个字符.");
			}
			return rightTrimForChars(string, char);
		}

		/**
		 * 暂不使用 
		 * @param haystack
		 * @param n
		 * @param needle
		 * @param startIndex
		 * @return 
		 * 
		 */		
		public static function nthIndexOf(haystack:String, n:uint, needle:String, startIndex:Number = 0):int {
			var result:int = startIndex;

			if (n >= 1) {
				result = haystack.indexOf(needle, result);

				for (var i:int = 1; result != -1 && i < n; i++) {
					result = haystack.indexOf(needle, result + 1);
				}
			}
			return result;
		}

		/**
		 * 判断给定的字符串是否以空格开始(即第一个字符是否为空格)
		 * @param a
		 * @return 
		 * 
		 */		
		public static function characterIsWhitespace(a:String):Boolean {
			return (a.charCodeAt(0) <= 32);
		}

		/**
		 * 判断给定的字符串是否以数字开始(即第一个字符是否为数字)
		 * @param a
		 * @return 
		 * 
		 */		
		public static function characterIsDigit(a:String):Boolean {
			var charCode:Number = a.charCodeAt(0);
			return (charCode >= 48 && charCode <= 57);
		}

		/**
		 * 比较两个字符串 
		 * @param a
		 * @param b
		 * @return 
		 * 
		 */		
		public static function naturalCompare(a:String, b:String):int {
			var ia:int = 0, ib:int = 0;
			var nza:int = 0, nzb:int = 0;
			var ca:String, cb:String;
			var result:int;
			var lowerCaseBeforeUpperCase:Boolean = true; // used to be a method argument, keep this

			// replace null values with empty strings
			if (!a)
				a = "";

			if (!b)
				b = "";

			/*if (!caseSensitive) {
			   a = a.toLowerCase();
			   b = b.toLowerCase();
			 }*/

			var stringsAreCaseInsensitiveEqual:Boolean = false;

			if (a.toLocaleLowerCase() == b.toLocaleLowerCase()) {
				stringsAreCaseInsensitiveEqual = true;
			} else {
				a = a.toLowerCase();
				b = b.toLowerCase();
			}

			while (true) {
				// only count the number of zeroes leading the last number compared
				nza = nzb = 0;

				ca = a.charAt(ia);
				cb = b.charAt(ib);

				// skip over leading spaces or zeros
				while (BOPStringUtils.characterIsWhitespace(ca) || ca == "0") {
					if (ca == "0") {
						nza++;
					} else {
						// only count consecutive zeroes
						nza = 0;
					}

					ca = a.charAt(++ia);
				}

				while (BOPStringUtils.characterIsWhitespace(cb) || cb == "0") {
					if (cb == "0") {
						nzb++;
					} else {
						// only count consecutive zeroes
						nzb = 0;
					}

					cb = b.charAt(++ib);
				}

				// process run of digits
				if (BOPStringUtils.characterIsDigit(ca) && BOPStringUtils.characterIsDigit(cb)) {
					if ((result = compareRight(a.substring(ia), b.substring(ib))) != 0) {
						return result;
					}
				}

				if (ca.length == 0 && cb.length == 0) {
					// The strings compare the same.  Perhaps the caller
					// will want to call strcmp to break the tie.
					return nza - nzb;
				}

				if (stringsAreCaseInsensitiveEqual) {
					// If the characters are in another case (upper or lower)
					if (ca != cb) {
						if (ca < cb) {
							return lowerCaseBeforeUpperCase ? +1 : -1;
						} else if (ca > cb) {
							return lowerCaseBeforeUpperCase ? -1 : +1;
						}
					}
				}

				if (ca < cb) {
					return -1;
				} else if (ca > cb) {
					return +1;
				}

				++ia;
				++ib;
			}

			return 0;
		}

		/**
		 * 反向比较两个字符串.
		 */
		private static function compareRight(a:String, b:String):int {
			var bias:int = 0;
			var ia:int = 0;
			var ib:int = 0;
			var ca:String;
			var cb:String;

			// The longest run of digits wins.  That aside, the greatest
			// value wins, but we can't know that it will until we've scanned
			// both numbers to know that they have the same magnitude, so we
			// remember it in BIAS.
			for (; ; ia++, ib++) {
				ca = a.charAt(ia);
				cb = b.charAt(ib);

				if (!BOPStringUtils.characterIsDigit(ca) && !BOPStringUtils.characterIsDigit(cb)) {
					return bias;
				} else if (!BOPStringUtils.characterIsDigit(ca)) {
					return -1;
				} else if (!BOPStringUtils.characterIsDigit(cb)) {
					return +1;
				} else if (ca < cb) {
					if (bias == 0) {
						bias = -1;
					}
				} else if (ca > cb) {
					if (bias == 0)
						bias = +1;
				} else if (ca.length == 0 && cb.length == 0) {
					return bias;
				}
			}

			return 0;
		}

		/**
		 * 将给定字符串用固定的分隔符分隔为数组. 
		 * @param string
		 * @param delimiters
		 * @return 
		 * 
		 */		
		public static function tokenizeToArray(string:String, delimiters:String):Array {
			var result:Array = [];
			var numCharacters:int = string.length;
			var delimiterFound:Boolean = false;
			var token:String = "";

			for (var i:int = 0; i < numCharacters; i++) {
				var character:String = string.charAt(i);

				if (delimiters.indexOf(character) == -1) {
					token += character;
				} else {
					result.push(token);
					token = "";
				}

				// add the last token if we reached the end of the string
				if (i == numCharacters - 1) {
					result.push(token);
				}
			}

			return result;
		}

		/**
		 * 将给定字符串中的变量(如{0},{1}...)替换为固定参数
		 * @param str
		 * @param rest
		 * @return
		 */
		public static function substitute(str:String, ... rest):String {
			if (str == null) {
				return '';
			}

			var len:uint = rest.length;
			var args:Array;
			if (len == 1 && rest[0] is Array) {
				args = rest[0] as Array;
				len = args.length;
			} else {
				args = rest;
			}

			for (var i:int = 0; i < len; i++) {
				var item:* = args[i];
				str = str.split('{' + i.toString() + '}').join((item != null) ? item.toString() : "[null]");
			}

			return str;
		}
		
		/**
		 * 在给定字符串前面加上某字符串,达到长度为给定长度.
		 * 如果给定长度小于源字符串长度,则直接返回源字符串.
		 *  
		 * @param input
		 * @param totalLength
		 * @param padCharacter
		 * @return 
		 * 
		 */		
		public static function padFront(input:String, totalLength:int, padCharacter:String):String
		{
			var difference:int = totalLength - input.length;
			if(difference <= 0) return input;
			
			for(var i:int = 0; i < difference; i++)
			{
				input = padCharacter + input;
			}
			return input;
		}
	}
}